package authserver.controller;


import authserver.vo.LoginResVo;
import authserver.vo.LoginVo;
import com.alibaba.fastjson.TypeReference;
import com.feign.member.MemberFeignService;
import com.feign.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

import static com.feign.constant.AuthServerConstant.LOGIN_USER;

@RestController
public class LoginController {

    @Autowired
    private MemberFeignService memberFeignService;

    /*@PostMapping("/login")
    public String login(LoginVo vo, RedirectAttributes attributes, HttpSession session) {

        //远程登录
        R login = memberFeignService.login(vo);

        if (login.getCode() == 0) {
            LoginResVo data = login.getData("data", new TypeReference<>() {
            });
            session.setAttribute(LOGIN_USER, data);
            return "redirect:http://gulimall.com";
        } else {
            Map<String, String> errors = new HashMap<>();
            errors.put("msg", login.getData("msg", new TypeReference<>() {
            }));
            attributes.addFlashAttribute("errors", errors);
            return "redirect:http://auth.gulimall.com/login.html";
        }
    }*/

    /*@PostMapping("/login")
    public void login(LoginVo vo, RedirectAttributes attributes, HttpSession session) {
        //远程登录
        R login = memberFeignService.login(vo);
        if (login.getCode() == 200) {
            // 登录成功
            LoginResVo data = login.getData("data", new TypeReference<>() {});
            session.setAttribute(LOGIN_USER, data);
        } else {
            Map<String, String> errors = new HashMap<>();
            errors.put("msg", login.getData("msg", new TypeReference<>() {}));
            attributes.addFlashAttribute("errors", errors);
        }
    }*/

}
